package com.github.lzyzsd.circleprogress.utils.properties;

import com.github.lzyzsd.circleprogress.ResourceTable;
import com.github.lzyzsd.circleprogress.utils.properties.IInterface.AttributeObserver;
import com.github.lzyzsd.circleprogress.utils.properties.IInterface.ResourcePropertyHolder;
import com.github.lzyzsd.circleprogress.utils.properties.model.CircleProgressModel;
import ohos.agp.components.AttrSet;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.global.resource.solidxml.TypedAttribute;

public class CircleProgressResPropertyHolder extends ResourcePropertyHolder<CircleProgressModel> {
    public CircleProgressResPropertyHolder(Context context, AttrSet attrSet) {
        super(context,attrSet);
    }

    @Override
    public CircleProgressModel obtainProperty() {
        model = new CircleProgressModel(getContext());
        AttrHelper patternElementHelper = new AttrHelper(getContext(), getAttrSet());
        patternElementHelper.getTypeAttribute("finishedColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (s) -> model.setFinishedColor(s));
        patternElementHelper.getTypeAttribute("unfinishedColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (s) -> model.setUnfinishedColor(s));
        patternElementHelper.getTypeAttribute("textColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (s) -> model.setTextColor(s));
        patternElementHelper.getTypeAttribute("textSize", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) (s) -> model.setTextSize(s));
        patternElementHelper.getTypeAttribute("prefixText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) (s) -> model.setPrefixText(s));
        patternElementHelper.getTypeAttribute("suffixText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) (s) -> model.setSuffixText(s));
        patternElementHelper.getTypeAttribute("max", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) s -> model.setMax(s));
        patternElementHelper.getTypeAttribute("progress", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) (s) -> model.setProgress(s));
        return model;
    }
}
